from mongodb_engine.database import DataBase
from app.config import DATABASE_NAME2 , DATALIST_SLUG
from exts import all_logger
collection = DataBase(DATABASE_NAME2,DATALIST_SLUG)

def get_slug(is_run):
    if is_run in False:
        all_logger.info("未检查到初始slug , 未初始化slug")
        return 0
    slug_list = collection.find({})
    if slug_list is None:
        basic_slug = 10000
        collection.insert({"slug":basic_slug})
        all_logger.info("未检查到初始slug , 初始化slug为10000")
        return basic_slug
    else:
        print(slug_list)
        slug = slug_list["slug"] + 1
        slug_list["slug"] += 1
        collection.update(slug_list,'_id')
        all_logger.info("已检查到初始slug , slug为{},已经对slug进行更新".format(slug))
        return slug

if __name__ == '__main__':
    print(get_slug())